/*
 * @lc app=leetcode.cn id=455 lang=javascript
 *
 * [455] 分发饼干
 */

// @lc code=start
/**
 * @param {number[]} g
 * @param {number[]} s
 * @return {number}
 */
var findContentChildren = function (g, s) {
  g.sort((a, b) => a - b);
  s.sort((a, b) => a - b);

  const len1 = g.length;
  const len2 = s.length;
  let p1 = 0;
  let p2 = 0;
  while (p1 < len1 && p2 < len2) {
    const num1 = g[p1];
    const num2 = s[p2];
    if (num2 >= num1) {
      p1++;
    }
    p2++;
  }
  return p1;
};
// @lc code=end
